﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Kompetition
{
    class Question
    {
        string question;
        Image image = null;
        string[] answers;

        public Question(string question, string imagePath, string[] answers)
        {
            if (string.IsNullOrEmpty(question))
                throw new ArgumentNullException("question");
            if (answers == null)
                throw new ArgumentNullException("answers");
            if (!string.IsNullOrEmpty(imagePath) && System.IO.File.Exists(imagePath))
                image = Image.FromFile(imagePath);

            this.question = question;
            this.answers = answers;
        }

        public bool IsCorrect(string answer)
        {
            double toCheck;
            try
            {
                if (answer.Contains("/"))
                    toCheck = int.Parse(answer.Split('/')[0]) / int.Parse(answer.Split('/')[1]);
                else
                    toCheck = double.Parse(answer);
            }
            catch { return false; }
            string check = toCheck.ToString();

            foreach (var pAnswer in answers)
            {
                if (pAnswer == check)
                    return true;
            }
            return false;
        }

        public string QuestionText
        {
            get { return question; }
        }

        public Image Image
        {
            get { return image; }
        }
    }
}
